layui.use(['form','layer','laydate','table','laytpl'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laydate = layui.laydate,
        laytpl = layui.laytpl,
        table = layui.table;

    var data = null;
    //新闻列表
    var tableIns = {
        elem: '#newsList',
        // url : '../../json/newsList.json',
        // url="/list?content=1",
        cellMinWidth : 95,
        page : true,
        height : "full-125",
        limit : 20,
        limits : [10,15,20,25],
        id : "newsListTable",
        cols : [[
            // {type: "checkbox", fixed:"left", width:50},
            {field: 'id', title: 'id', align:"center"},
            {field: 'name', title: 'name', align:"center"},
            {field: 'mem', title: 'mem(Kb)', align:"center", sort:true },
            {field: 'cpu', title: 'cpu', align:'center', sort:true },
            {field: 'message', title: 'message',  align:'center', sort:true },
            {field: 'mqlen', title: 'mqlen', align:'center', sort:true },
            {field: 'task', title: 'task', align:'center', sort:true },
        ]],
        data : []
    }

    //是否置顶
    form.on('switch(newsTop)', function(data){
        var index = layer.msg('修改中，请稍候',{icon: 16,time:false,shade:0.8});
        setTimeout(function(){
            layer.close(index);
            if(data.elem.checked){
                layer.msg("置顶成功！");
            }else{
                layer.msg("取消置顶成功！");
            }
        },500);
    })



    //list
    $(".list_btn").on("click",function(){
        var url = "list?content=1"; //参数
        $.ajax({
            url:url,
            type:'get',
            data:1,
            dataType:'json',
            headers:{'token':1},
            beforeSend:function () {
                // this.layerIndex = layer.load(0, { shade: [0.5, '#393D49'] });
                // console.log("__________2_______")
            },
            success:function(data){
                // 返回
                // var data = JSON.parse(data)
                if(data.status == 'error'){                                       
                    layer.msg(data.msg,{icon: 5});//失败的表情
                    return;
                }else if(data.status == 'success'){                    
                    
                    console.log("_______success__________",data)
                    // layer.msg("登录成功!")
                    var itemData = data.data
                    $.extend(tableIns, {data: itemData});
                    // console.log(tableIns);
                    table.reload("newsListTable", tableIns);  
                    data=null;                   
                }
            },
            complete: function () {
                console.log("__________complete_______")
            },
        });
    });

    //mem
    $(".mem_btn").on("click", function(){
        var url = "mem?content=1"; //参数
        var require = {
            url:url,
            type:"get",
            data:1,
            dataType:"json",
            headers:{"token":1},
            success:function(data){
                if(data.status == "success"){
                    console.log("_______success__________",data)                    
                    var itemData = data.data
                    $.extend(tableIns, {data: itemData});   //内容合并                
                    table.render(tableIns);  
                    data=null;                    
                }
            }
        }
        $.ajax(require);
    });            

    //stat
    $(".stat_btn").on("click", function(){
        var url = "stat?content=1"; //参数
        var require = {
            url:url,
            type:"get",
            data:1,
            dataType:"json",
            headers:{"token":1},
            success:function(data){
                if(data.status == "success"){
                    console.log("_______success__________",data)                    
                    var itemData = data.data
                    $.extend(tableIns, {data: itemData});   //内容合并                
                    table.render(tableIns);  
                    data=null;                    
                }
            }
        }
        $.ajax(require);
    });    
    // 表格初始化 ------------------
    function init (){         
        console.log("__________表格初始化_______")                                             
        var url = "xx/list";
        $.ajax({
            url:url,
            type:'get',
            data:1,
            dataType:'json',
            headers:{'token':1},
            success:function(data){
                if(data.status == 'success'){                    
                    console.log("_______success__________",data)
                    // layer.msg("登录成功!")
                    var itemData = data.data
                    $.extend(tableIns, {data: itemData}); //内容合并
                    console.log(tableIns);
                    table.render(tableIns);  
                    data=null;                   
                }
            },
        });         

              
        data=null;               
    }
    // 页面初始化---------------------------------
    init();

})